<?php
/* SolidCMS configuration file v1.0.0
 * under conditions and terms of gnu/gpl
 * Oleg Kasian 2011, o-kasian@yandex.ru
 */

// WARNING!!! Do not change any comments in class body.

defined('EXEC') or die('No direct access');

class config {
	//Properties array
	private static $values=array(
		'dbhost'=>'localhost',
		'dbuser'=>'root',
		'dbpass'=>'crRrtphde',
		'dbname'=>'test',
		'dbprefix'=>'ts_',
		'core_path'=>'core/',
		'sandbox'=>'0',
		'administrate'=>'1',
		'log'=>'1',
		'rewrite'=>'0',
		'site_enabled'=>'1',
		'site_name'=>'New site',
		'site_description'=>'New site',
		'site_tags'=>'tag, new, site',
		'site_lang'=>'en'
	);
	private static $old_values=array();
	private static $set=array();
	
	//Class has no instance
	private function __construct() {}
	private function __clone() {}
	private function init() {
		self::$old_values=self::$values;
	}
	
	//Rewrite configuration with currently set values
	public static function rewrite() {
		if(count(self::$set)) {
			$buffer=file_get_contents(__FILE__);
			foreach(self::$set as $index=>$value) {
				if(isset(self::$old_values[$index])) {
					$search = "/'$index'=>'(.*?)'/";
					$replace = "'$index'=>'$value'";
					$buffer = preg_replace($search, $replace, $buffer);
				} else {
					$search = '/\$values=array\(/';
					$replace = '$values=array(\n\t\t\''.$index."'=>'$value',";
					$buffer = preg_replace($search, $replace, $buffer);
				}
			}
			$fp=fopen(__FILE__, 'w');
			fwrite($fp, $buffer);
			fclose($fp);
		} else return false;
	}
	
	//Returns config value
	public static function get($value) {
		if(isset(self::$values[strtolower($value)])) return self::$values[strtolower($value)];
		else return false;
	}
	
	//Sets config $value
	public static function set($valuename, $value) {
		self::$values[strtolower($valuename)]=$value;
		self::$set[strtolower($valuename)]=$value;
	}
}
?> 
